home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5693 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.mistral.co.uk!usenet
  2. From: mikebarnard@mistral.co.uk (Mike Barnard)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Initialising structure members - help please!
  5. Date: Tue, 20 Feb 1996 11:54:07 GMT
  6. Organization: Mistral Internet (Brighton)
  7. Message-ID: <4gckb1$77e@news.mistral.co.uk>
  8. References: <4gb8hn$3m8@news.mistral.co.uk> <31298EF1.5F2C@cmt.lpr.mail.carel.fi>
  9. NNTP-Posting-Host: l56.mistral.co.uk
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Hi Aril and Peter.
  13.  
  14. Thanks for your replies.
  15.  
  16. You said...
  17.  
  18. >>one.number = 1;
  19. >>one.description = "1.   Calculate a minefield";
  20.  
  21. >You can't copy C strings with an "=".  You must use the strcpy() function.
  22.  
  23. and...
  24.  
  25. >Since you declared 'description' as an array of chars, use strcpy(one.description, 
  26. >"whatever string"); Be sure you won't use longer strings than the space available. A 
  27. >better approach would be to declare 'decription' as a 'char *' and then malloc 
  28. >enough space for whatever string you're going to place into it. (Also, your syntax 
  29. >would work in that case.) The last two will work if you add & in front of them.
  30.  
  31. Thanks, I'll look at what this means. But as a learning question, (not
  32. an argumentative one!!!),  why does this good old boy work then?
  33.  
  34. char name[]="An array of characters";
  35.  
  36. Surely "name" is an array of characters as is my "description"? It
  37. works here. Doesn't it? This leads me on to another question actually,
  38. but I'll start another thread with it I think. 
  39.  
  40. Thanks again.
  41.  
  42. ---
  43. Mic.
  44. From very windy and now snowy Worthing; England.
  45. mikebarnard@mistral.co.uk
  46.  
  47. (I just lost 4 fence panels to the wind here! The cost of
  48. replacing them could have bought me a new windows compiler!)
  49.  
  50.